# coding=utf-8
# 描述性统计
import sys
import pandas as pd
import numpy as np
from pandas.io.json import build_table_schema
pd.set_option('display.width',1000)
# path:读取的数据
path = sys.argv[1]
# names_filename:表头信息文件名，将从目标位置进行查找
names_filename = sys.argv[2]
out=sys.argv[3]
excel_out=sys.argv[4]
names = []
with open(names_filename, 'r') as f:
    line = f.readline()
    while line:
        line=line.rstrip('\n')
        elements = line.split(',')
        for element in elements:
            names.append(element)
        line = f.readline()
#将结果给names
ukdate = pd.read_csv(path, names=names)
# 数据不能为空
if ukdate.empty != True:
    # 判断数据类型
    if(ukdate.ndim == 2):
        ds=pd.DataFrame(ukdate.describe(include='all'))
        ds.to_json(out,orient='table')
        writer = pd.ExcelWriter(excel_out)
        ds.to_excel(writer,'Sheet1')
        writer.save()
else:
    print "no data"
